#ifndef __GLES2RenderTexture_H__
#define __GLES2RenderTexture_H__

#include "GLES2Texture.h"

namespace PVM
{
	class GLES2HardwarePixelBuffer;
	
	struct GLES2SurfaceDesc
	{
	public:
		GLES2HardwarePixelBuffer* buffer;
		size_t zoffset;
		uint numSamples;
		
		GLES2SurfaceDesc(): buffer(0), zoffset(0), numSamples(0) {}
	};
	
	class GLES2RenderTexture : public RenderTexture
	{
	public:
		GLES2RenderTexture(const std::string& name, const GLES2SurfaceDesc& target, bool writeGamma, uint fsaa);
		virtual ~GLES2RenderTexture();
		bool requiresTextureFlipping() const {return true;}
	};
	
	class GLES2RTTManager : public Singleton<GLES2RTTManager>
	{
	public:
		virtual ~GLES2RTTManager();
		virtual RenderTexture* createRenderTexture(const std::string& name, const GLES2SurfaceDesc& target, bool writeGamma, uint fsaa) = 0;
		virtual bool checkFormat(PixelFormat format) = 0;
		virtual void bind(RenderTarget* target) = 0;
		virtual void unbind(RenderTarget* target) = 0;
		virtual void getBestDepthStencil(GLenum internalFormat, GLenum* depthFormat, GLenum* stencilFormat)
		{
			*depthFormat = GL_NONE;
			*stencilFormat = GL_NONE;
		}
		
		virtual MultiRenderTarget* createMultiRenderTarget(const std::string& name);
		
		virtual PixelFormat getSupportedAlternative(PixelFormat format);
	};
	
	class GLES2CopyingRTTManager;
	class GLES2CopyingRenderTexture : public GLES2RenderTexture
	{
	public:
		GLES2CopyingRenderTexture(GLES2CopyingRTTManager* manager,
								  const std::string& name,
								  const GLES2SurfaceDesc& target,
								  bool writeGamma, uint fsaa);
		
		virtual void getCustomAttribute(const std::string& name, void* pData);
	};
	
	class GLES2CopyingRTTManager : public GLES2RTTManager
	{
	public:
		GLES2CopyingRTTManager();
		virtual ~GLES2CopyingRTTManager();
		
		virtual RenderTexture* createRenderTexture(const std::string& name, const GLES2SurfaceDesc& target, bool writeGamma, uint fsaa);
		virtual bool checkFormat(PixelFormat format);
		virtual void bind(RenderTarget* target);
		virtual void unbind(RenderTarget* target);
	};
}

#endif